package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.domain.ZhDeptInfo;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 站点 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/zhDeptInfo")
public class ZhDeptInfoController extends BaseController
{
    private String prefix = "system/zhDeptInfo";
	
	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptInfo:view")
	@GetMapping()
	public String zhDeptInfo(ZhDeptInfo zhDeptInfo,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptInfo.getParams())));
		return prefix + "/zhDeptInfo";

	}
	
	/**
	 * 查询站点列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhDeptInfo zhDeptInfo,ModelMap mmap)
	{
		startPage();
		// 这里与其他接口不同，需要条件筛选dept。
		List<ZhDeptInfo> zhDeptInfos = zhDeptInfoService.selectZhDeptInfoList(zhDeptInfo);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptInfo.getParams())));
		return getDataTable(zhDeptInfos);
	}
	
	
	/**
	 * 导出站点列表
	 */
	@RequiresPermissions("system:zhDeptInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhDeptInfo zhDeptInfo)
    {
    	List<ZhDeptInfo> list = zhDeptInfoService.selectZhDeptInfoList(zhDeptInfo);
        ExcelUtil<ZhDeptInfo> util = new ExcelUtil<ZhDeptInfo>(ZhDeptInfo.class);
        return util.exportExcel(list, "zhDeptInfo");
    }
	
	/**
	 * 新增站点
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存站点
	 */
	@RequiresPermissions("system:zhDeptInfo:add")
	@Log(title = "站点", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhDeptInfo zhDeptInfo)
	{		
		return toAjax(zhDeptInfoService.insertZhDeptInfo(zhDeptInfo));
	}

	/**
	 * 修改站点
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhDeptInfo zhDeptInfo = zhDeptInfoService.selectZhDeptInfoById(id);
		mmap.put("zhDeptInfo", zhDeptInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存站点
	 */
	@RequiresPermissions("system:zhDeptInfo:edit")
	@Log(title = "站点", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhDeptInfo zhDeptInfo)
	{		
		return toAjax(zhDeptInfoService.updateZhDeptInfo(zhDeptInfo));
	}
	
	/**
	 * 删除站点
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptInfo:remove")
	@Log(title = "站点", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhDeptInfo zhDeptInfo,String ids)
	{		
		return toAjax(zhDeptInfoService.deleteZhDeptInfoByIds(ids));
	}
	
}
